/*
 * @Description: 原型模式
 * @Author: zzj
 * @Date: 2021-09-07 11:25:27
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-07 11:40:27
 */

//原型模式
function Dog(){}
//在prototype中定义的属性和方法，所有的实例对象都共享
Dog.prototype.name = "xiaobai";
Dog.prototype.age = 2;
Dog.prototype.text = {  //在原型模式创建时，如果属性是引用数据类型，可能会有误操作
    t:"is dog",
}
Dog.prototype.sayName = function(){
    console.log(this.name);
}
var dog1 = new Dog();
var dog2 = new Dog();
dog1.text.t = "is white dog";
console.log(dog2.text.t);
dog1.sayName();
dog1.name = "123";
console.log(dog1)
console.log(dog1.name);

